package service

import (
	"context"

	v1 "paint-guess/api/paint_guess/v1"
	"paint-guess/internal/biz"
)

type PaintGuessService struct {
	v1.UnimplementedPaintGuessServer

	uc *biz.PaintGuessUsecase
}

func NewPaintGuessService(uc *biz.PaintGuessUsecase) *PaintGuessService {
	return &PaintGuessService{uc: uc}
}

// 查看房间人数，判断是否需要设置密码
func (pg *PaintGuessService) GetRoomPersonNum(ctx context.Context, req *v1.GetRoomPersonNumRequest) (*v1.GetRoomPersonNumReply, error) {
	reply, err := pg.uc.GetRoomPersonNum(ctx, req)
	if err != nil {
		return nil, err
	}
	return reply, nil
}

// 没有人则创建房间，有人则进入房间
func (pg *PaintGuessService) JoinRoom(ctx context.Context, req *v1.JoinRoomRequest) (*v1.JoinRoomReply, error) {
	reply, err := pg.uc.JoinRoom(ctx, req)
	if err != nil {
		return nil, err
	}
	return reply, nil
}

func (pg *PaintGuessService) ExitRoom(ctx context.Context, req *v1.ExitRoomRequest) (*v1.ExitRoomReply, error) {
	reply, err := pg.uc.ExitRoom(ctx, req)
	if err != nil {
		return nil, err
	}
	return reply, nil
}

func (pg *PaintGuessService) GetToken(ctx context.Context, req *v1.GetTokenRequest) (*v1.GetTokenReply, error) {
	reply, err := pg.uc.GetToken(ctx, req)
	if err != nil {
		return nil, err
	}
	return reply, nil
}

func (pg *PaintGuessService) GetRoomUserMsg(ctx context.Context, req *v1.GetRoomUserMsgRequest) (*v1.GetRoomUserMsgReply, error) {
	reply, err := pg.uc.GetRoomUserMsg(ctx, req)
	if err != nil {
		return nil, err
	}
	return reply, nil
}

func (pg *PaintGuessService) UpdateUserScore(ctx context.Context, req *v1.UpdateScoreRequest) (*v1.UpdateScoreReply, error) {
	reply, err := pg.uc.UpdateUserScore(ctx, req)
	if err != nil {
		return nil, err
	}
	return reply, nil
}
